package com.umeng.analytics.pro;

import android.content.ComponentName;
import android.content.Context;
import android.content.Intent;
import android.content.ServiceConnection;
import android.os.IBinder;
import android.os.IInterface;
import android.os.Parcel;
import android.os.RemoteException;

import java.io.IOException;
import java.util.concurrent.LinkedBlockingQueue;

public class br {
    static final class a {
        private final String a;
        private final boolean b;

        a(String arg1, boolean arg2) {

            this.a = arg1;
            this.b = arg2;
        }

        static String a(a arg1) {
            return arg1.b();
        }

        public final boolean a() {
            return this.b;
        }

        private String b() {
            return this.a;
        }
    }

    static final class b implements ServiceConnection {
        boolean a;
        private final LinkedBlockingQueue b;

        private b() {

            this.a = false;
            this.b = new LinkedBlockingQueue(1);
        }

        public final IBinder a() throws InterruptedException {
            if (this.a) {
                throw new IllegalStateException();
            }

            this.a = true;
            return (IBinder) this.b.take();
        }

        public final void onServiceConnected(ComponentName arg2, IBinder arg3) {
            try {
                this.b.put(arg3);
            } catch (InterruptedException v0) {
            }
        }

        public final void onServiceDisconnected(ComponentName arg1) {
        }
    }

    static final class c implements IInterface {
        private IBinder a;

        public c(IBinder arg1) {

            this.a = arg1;
        }

        public final String a() throws RemoteException {
            String v0_1;
            Parcel v1 = Parcel.obtain();
            Parcel v2 = Parcel.obtain();
            try {
                v1.writeInterfaceToken("com.google.android.gms.ads.identifier.internal.IAdvertisingIdService");
                this.a.transact(1, v1, v2, 0);
                v2.readException();
                v0_1 = v2.readString();
            } catch (Throwable v0) {
                v2.recycle();
                v1.recycle();
                throw v0;
            }

            v2.recycle();
            v1.recycle();
            return v0_1;
        }

        public final boolean a(boolean arg8) throws RemoteException {
            int v2;
            boolean v0 = true;
            Parcel v3 = Parcel.obtain();
            Parcel v4 = Parcel.obtain();
            try {
                v3.writeInterfaceToken("com.google.android.gms.ads.identifier.internal.IAdvertisingIdService");
                if (arg8) {
                    v2 = 1;
                } else {
                    v2 = 0;
                }

                v3.writeInt(v2);
                this.a.transact(2, v3, v4, 0);
                v4.readException();
                if (v4.readInt() == 0) {
                    v0 = false;
                }
            } catch (Throwable v0_1) {

            } finally {
                v4.recycle();
                v3.recycle();
            }


            return v0;
        }

        public final IBinder asBinder() {
            return this.a;
        }
    }

    public br() {

    }

    public static String a(Context arg2) {
        String v0 = null;
        try {
            a v1_1 = br.b(arg2);
            if (v1_1 == null) {
                return v0;
            }

            v0 = a.a(v1_1);
        } catch (Exception v1) {
        }

        return v0;
    }

    private static a b(Context arg5) throws Exception {
        a v2;
        try {
            arg5.getPackageManager().getPackageInfo("com.android.vending", 0);
        } catch (Exception v0) {
            throw v0;
        }

        b v1 = new b();
        Intent v0_1 = new Intent("com.google.android.gms.ads.identifier.service.START");
        v0_1.setPackage("com.google.android.gms");
        if (arg5.bindService(v0_1, ((ServiceConnection) v1), 1)) {
            try {
                c v0_3 = new c(v1.a());
                v2 = new a(v0_3.a(), v0_3.a(true));
            } catch (Exception v0) {
                try {
                    throw v0;
                } catch (Throwable v0_2) {
                    arg5.unbindService(((ServiceConnection) v1));
                    throw v0_2;
                }
            }

            arg5.unbindService(((ServiceConnection) v1));
            return v2;
        }

        throw new IOException("Google Play connection failed");
    }
}

